home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Dev / misc / WHDLoad_dev.lha / WHDLoad / Src / slave-examples / kick31.asm < prev    next >
Encoding:
Assembly Source File  |  2003-12-09  |  7.5 KB  |  402 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Modul.    kick31.asm
  3. ;  :Contents.    kickstart 3.1 booter
  4. ;  :Author.    Wepl
  5. ;  :Version.    $Id: kick31.asm 1.3 2003/12/09 11:18:09 wepl Exp wepl $
  6. ;  :History.    04.03.03 started
  7. ;        22.06.03 rework for whdload v16
  8. ;  :Requires.    kick31.s
  9. ;  :Copyright.    Public Domain
  10. ;  :Language.    68000 Assembler
  11. ;  :Translator.    Barfly V2.9
  12. ;  :To Do.
  13. ;---------------------------------------------------------------------------*
  14.  
  15.     INCDIR    Includes:
  16.     INCLUDE    whdload.i
  17.     INCLUDE    whdmacros.i
  18.     INCLUDE    lvo/dos.i
  19.  
  20.     IFD BARFLY
  21.     OUTPUT    "wart:.debug/Kick31.Slave"
  22.     BOPT    O+                ;enable optimizing
  23.     BOPT    OG+                ;enable optimizing
  24.     BOPT    ODd-                ;disable mul optimizing
  25.     BOPT    ODe-                ;disable mul optimizing
  26.     BOPT    w4-                ;disable 64k warnings
  27.     BOPT    wo-                ;disable optimize warnings
  28.     SUPER
  29.     ENDC
  30.  
  31. ;============================================================================
  32.  
  33. CHIPMEMSIZE    = $80000
  34. FASTMEMSIZE    = $80000
  35. NUMDRIVES    = 5
  36. WPDRIVES    = %1111
  37.  
  38. ;BLACKSCREEN
  39. BOOTBLOCK
  40. BOOTDOS
  41. ;BOOTEARLY
  42. CBDOSLOADSEG
  43. CBDOSREAD
  44. CACHE
  45. DEBUG
  46. DOSASSIGN
  47. ;DISKSONBOOT
  48. ;FONTHEIGHT    = 8
  49. HDINIT
  50. ;INITAGA
  51. ;INIT_AUDIO
  52. ;INIT_GADTOOLS
  53. ;INIT_MATHFFP
  54. HRTMON
  55. ;IOCACHE    = 1024
  56. ;MEMFREE    = $200
  57. ;NEEDFPU
  58. ;POINTERTICKS    = 1
  59. ;STACKSIZE    = 6000
  60. ;TRDCHANGEDISK
  61.  
  62. ;============================================================================
  63.  
  64. slv_Version    = 16
  65. slv_Flags    = WHDLF_NoError|WHDLF_Examine
  66. slv_keyexit    = $59    ;F10
  67.  
  68. ;============================================================================
  69.  
  70.     INCLUDE    Sources:whdload/kick31.s
  71.  
  72. ;============================================================================
  73.  
  74.     IFD BARFLY
  75.     IFND    .passchk
  76.     DOSCMD    "WDate  >T:date"
  77. .passchk
  78.     ENDC
  79.     ENDC
  80.  
  81. slv_CurrentDir        dc.b    "wb31",0
  82. slv_name        dc.b    "Kickstarter for 40.068",0
  83. slv_copy        dc.b    "1985-93 Commodore-Amiga Inc.",0
  84. slv_info        dc.b    "adapted for WHDLoad by Wepl",10
  85.         dc.b    "Version 0.2 "
  86.     IFD BARFLY
  87.         INCBIN    "T:date"
  88.     ENDC
  89.         dc.b    0
  90.     EVEN
  91.  
  92. ;============================================================================
  93. ; entry before any diskaccess is performed, no dos.library available
  94.  
  95.     IFD BOOTEARLY
  96.  
  97. _bootearly    blitz
  98.         rts
  99.  
  100.     ENDC
  101.  
  102. ;============================================================================
  103. ; bootblock from "Disk.1" has been loaded, no dos.library available
  104.  
  105.     IFD BOOTBLOCK
  106.  
  107. ; A0 = buffer (1024 bytes)
  108. ; A1 = ioreq
  109. ; A6 = execbase
  110.  
  111. _bootblock    blitz
  112.         jmp    (12,a4)
  113.  
  114.     ENDC
  115.  
  116. ;============================================================================
  117. ; like a program from "startup-sequence" executed, full dos process,
  118. ; HDINIT is required
  119.  
  120. ; the following example is extensive because it saves all registers and
  121. ;   restores them before executing the program, the reason for this that some
  122. ;   programs (e.g. MANX Aztec-C) require specific registers properly setup on
  123. ;   calling
  124. ; in most cases a simpler routine is sufficient :-)
  125.  
  126.     IFD BOOTDOS
  127.  
  128. _bootdos    lea    (_saveregs,pc),a0
  129.         movem.l    d1-d6/a2-a6,(a0)
  130.         move.l    (a7)+,(44,a0)
  131.  
  132.     ;open doslib
  133.         lea    (_dosname,pc),a1
  134.         move.l    (4),a6
  135.         jsr    (_LVOOldOpenLibrary,a6)
  136.         lea    (_dosbase,pc),a0
  137.         move.l    d0,(a0)
  138.         move.l    d0,a6            ;A6 = dosbase
  139.  
  140.     ;assigns
  141.         lea    (_disk1,pc),a0
  142.         sub.l    a1,a1
  143.         bsr    _dos_assign
  144.  
  145.     ;check version
  146.         lea    (_program,pc),a0
  147.         move.l    a0,d1
  148.         move.l    #MODE_OLDFILE,d2
  149.         jsr    (_LVOOpen,a6)
  150.         move.l    d0,d1
  151.         beq    .end
  152.         move.l    #300,d3
  153.         sub.l    d3,a7
  154.         move.l    a7,d2
  155.         jsr    (_LVORead,a6)
  156.         move.l    d3,d0
  157.         move.l    a7,a0
  158.         move.l    (_resload,pc),a2
  159.         jsr    (resload_CRC16,a2)
  160.         add.l    d3,a7
  161.         
  162.         cmp.w    #$dd8e,d0
  163.         beq    .versionok
  164.         pea    TDREASON_WRONGVER
  165.         jmp    (resload_Abort,a2)
  166. .versionok
  167.  
  168.     ;load exe
  169.         lea    (_program,pc),a0
  170.         move.l    a0,d1
  171.         jsr    (_LVOLoadSeg,a6)
  172.         move.l    d0,d7            ;D7 = segment
  173.         beq    .end
  174.  
  175.     ;patch
  176.         lea    (_pl_program,pc),a0
  177.         move.l    d7,a1
  178.         jsr    (resload_PatchSeg,a2)
  179.  
  180.     IFD DEBUG
  181.     ;set debug
  182.         clr.l    -(a7)
  183.         move.l    d7,-(a7)
  184.         pea    WHDLTAG_DBGSEG_SET
  185.         move.l    a7,a0
  186.         jsr    (resload_Control,a2)
  187.         add.w    #12,a7
  188.     ENDC
  189.  
  190.     ;call
  191.         move.l    d7,a1
  192.         add.l    a1,a1
  193.         add.l    a1,a1
  194.         moveq    #_args_end-_args,d0
  195.         lea    (_args,pc),a0
  196.         movem.l    (_saveregs,pc),d1-d6/a2-a6
  197.         jsr    (4,a1)
  198.  
  199.     ;remove exe
  200.         move.l    d7,d1
  201.         move.l    (_dosbase,pc),a6
  202.         jsr    (_LVOUnLoadSeg,a6)
  203.  
  204.     IFD QUIT_AFTER_PROGRAM_EXIT
  205.         pea    TDREASON_OK
  206.         jmp    (resload_Abort,a2)
  207.     ELSE
  208.     ;remove exe
  209.         move.l    d7,d1
  210.         move.l    (_dosbase,pc),a6
  211.         jsr    (_LVOUnLoadSeg,a6)
  212.     ENDC
  213.  
  214. .end        moveq    #0,d0
  215.         move.l    (_saverts,pc),-(a7)
  216.         rts
  217.  
  218. _pl_program    PL_START
  219.         PL_END
  220.  
  221. _disk1        dc.b    "mydisk1",0
  222. _program    dc.b    "program to start",0
  223. _args        dc.b    10
  224. _args_end    dc.b    0
  225.     EVEN
  226.  
  227. _saveregs    ds.l    11
  228. _saverts    dc.l    0
  229. _dosbase    dc.l    0
  230.  
  231.     ENDC
  232.  
  233. ;============================================================================
  234. ; callback/hook which gets executed after each successful call to dos.LoadSeg
  235. ; can also be used instead of _bootdos, requires the presence of
  236. ; "startup-sequence"
  237.  
  238. ; the following example uses a parameter table to patch different executables
  239. ; after they get loaded
  240.  
  241.     IFD CBDOSLOADSEG
  242.  
  243. ; D0 = BSTR name of the loaded program as BCPL string
  244. ; D1 = BPTR segment list of the loaded program as BCPL pointer
  245.  
  246. _cb_dosLoadSeg    lsl.l    #2,d0        ;-> APTR
  247.         move.l    d0,a0
  248.         moveq    #0,d0
  249.         move.b    (a0)+,d0    ;D0 = name length
  250.     ;remove leading path
  251.         move.l    a0,a1
  252.         move.l    d0,d2
  253. .2        move.b    (a1)+,d3
  254.         subq.l    #1,d2
  255.         cmp.b    #":",d3
  256.         beq    .1
  257.         cmp.b    #"/",d3
  258.         beq    .1
  259.         tst.l    d2
  260.         bne    .2
  261.         bra    .3
  262. .1        move.l    a1,a0        ;A0 = name
  263.         move.l    d2,d0        ;D0 = name length
  264.         bra    .2
  265. .3    ;get hunk length sum
  266.         move.l    d1,a1        ;D1 = segment
  267.         moveq    #0,d2
  268. .add        add.l    a1,a1
  269.         add.l    a1,a1
  270.         add.l    (-4,a1),d2    ;D2 = hunks length
  271.         subq.l    #8,d2        ;hunk header
  272.         move.l    (a1),a1
  273.         move.l    a1,d7
  274.         bne    .add
  275.     ;search patch
  276.         lea    (.patch,pc),a1
  277. .next        move.l    (a1)+,d3
  278.         movem.w    (a1)+,d4-d5
  279.         beq    .end
  280.         cmp.l    d2,d3        ;length match?
  281.         bne    .next
  282.     ;compare name
  283.         lea    (.patch,pc,d4.w),a2
  284.         move.l    a0,a3
  285.         move.l    d0,d6
  286. .cmp        move.b    (a3)+,d7
  287.         cmp.b    #"a",d7
  288.         blo    .l
  289.         cmp.b    #"z",d7
  290.         bhi    .l
  291.         sub.b    #$20,d7
  292. .l        cmp.b    (a2)+,d7
  293.         bne    .next
  294.         subq.l    #1,d6
  295.         bne    .cmp
  296.         tst.b    (a2)
  297.         bne    .next
  298.     ;patch
  299.         lea    (.patch,pc,d5.w),a0
  300.         move.l    d1,a1
  301.         move.l    (_resload,pc),a2
  302.         jsr    (resload_PatchSeg,a2)
  303.     ;end
  304. .end
  305.     IFD DEBUG
  306.     ;set debug
  307.         clr.l    -(a7)
  308.         move.l    d1,-(a7)
  309.         pea    WHDLTAG_DBGSEG_SET
  310.         move.l    a7,a0
  311.         move.l    (_resload,pc),a2
  312.         jsr    (resload_Control,a2)
  313.         add.w    #12,a7
  314.     ENDC
  315.         rts
  316.  
  317. PATCH    MACRO
  318.         dc.l    \1        ;cumulated size of hunks (not filesize!)
  319.         dc.w    \2-.patch    ;name
  320.         dc.w    \3-.patch    ;patch list
  321.     ENDM
  322.  
  323. .patch        PATCH    2516,.n_run,_p_run2568
  324.         dc.l    0
  325.  
  326.     ;all upper case!
  327. .n_run        dc.b    "RUN",0
  328.     EVEN
  329.  
  330. _p_run2568    PL_START
  331.     ;    PL_P    0,.1
  332.         PL_END
  333.  
  334.     ENDC
  335.  
  336. ;============================================================================
  337. ; callback/hook which gets executed after each successful call to
  338. ; dos.LoadRead
  339.  
  340. ; the following example uses a parameter table to patch different files
  341. ; after they get loaded
  342.  
  343.     IFD CBDOSREAD
  344.  
  345. ; D0 = ULONG bytes read
  346. ; D1 = ULONG offset in file
  347. ; A0 = CPTR name of file
  348. ; A1 = APTR memory buffer
  349.  
  350. _cb_dosRead
  351.         move.l    a0,a2
  352. .1        tst.b    (a2)+
  353.         bne    .1
  354.         lea    (.name,pc),a3
  355.         move.l    a3,a4
  356. .2        tst.b    (a4)+
  357.         bne    .2
  358.         sub.l    a4,a2
  359.         add.l    a3,a2        ;first char to check
  360. .4        move.b    (a2)+,d2
  361.         cmp.b    #"A",d2
  362.         blo    .3
  363.         cmp.b    #"Z",d2
  364.         bhi    .3
  365.         add.b    #$20,d2
  366. .3        cmp.b    (a3)+,d2
  367.         bne    .no
  368.         tst.b    d2
  369.         bne    .4
  370.  
  371.     ;check position
  372.         move.l    d0,d2
  373.         add.l    d1,d2
  374.         lea    (.data,pc),a2
  375.         moveq    #0,d3
  376. .next        movem.w    (a2)+,d3-d4
  377.         tst.w    d3
  378.         beq    .no
  379.         cmp.l    d1,d3
  380.         blo    .next
  381.         cmp.l    d2,d3
  382.         bhs    .next
  383.         sub.l    d1,d3
  384.         move.b    d4,(a1,d3.l)
  385.         bra    .next
  386.  
  387. .no        rts
  388.  
  389. .name        dc.b    "tables01",0    ;lower case!
  390.     EVEN
  391.     ;offset, new data
  392. .data        dc.w    $4278,$c    ;original = 0b
  393.         dc.w    $45b4,$c    ;original = 0b
  394.         dc.w    0
  395.  
  396.     ENDC
  397.  
  398. ;============================================================================
  399.  
  400.     END
  401.  
  402.